/**
 *
 */
package com.yongbao.common.enums;

import com.yongbao.common.exception.BusinessException;

/**
 * @author zhanghong
 */
public enum ErrorCode {
    /**
     *
     */
    ERR_REMOTE_INVOKE("500", "远程调用错误"),

    INTER_ERR("500", "服务器内部错误"),
    UN_CATCH_EXCEPTION("1000001", "未捕获的错误, 请联系管理员"),
    PARAM_ERROR("1000002", "参数错误"),
    NET_ERR("1000003", "网络延迟，请稍后重试"),
    USER_OR_PWD_INVALID("1000004", "账号或者密码错误"),

    NOT_LOGIN("5000000", "未登录"),
    ERR_SEND_SMS_CODE("5000001", "短信验证码，发送失败"),
    ERR_SEND_SMS_CODE_TIMES("5000002", "今日发送验证码机会已用完"),
    ERR_VERIFY_CODE("5000003", "验证码错误"),
    ERR_LOGIN("5000004", "登录失败"),
    WECHAT_AUTH_LOGIN_FAIL("5000005", "微信授权登录失败"),
    ERR_UPLOAD_FILE("5000006", "文件上传失败"),
    ERR_NO_PERMISSION("5000007", "无操作权限"),
    ERR_REFUND("5000008", "退款失败"),

    //
    EXIST_BIND_ROLE_ERR("6000001", "存在绑定的角色，不可删除"),
    EXIST_BIND_USER_ERR("6000002", "存在绑定的用户，不可删除"),
    ADMIN_IS_EXIST("6000003", "该用户名称已存在"),
    ROLE_IS_EXIST("6000004", "该角色名称已存在"),
    R_CODE_ERR("6000005", "该用户R号不存在"),
    BIND_ERR("6000006", "请先完成书籍绑定");
    ;
    private String code;
    private String msg;

    private ErrorCode(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static ErrorCode getByCode(String code) {
        for (ErrorCode errorCode : values()) {
            if (errorCode.getCode().equals(code)) {
                return errorCode;
            }
        }
        throw new BusinessException(UN_CATCH_EXCEPTION);
    }

}
